package com.sdry.service.impl.jyy;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.sdry.model.jyy.ReceiveDetailQuality;
import com.sdry.model.jyy.Workload;
import com.sdry.model.lz.*;
import com.sdry.model.zc.ZcInventoryInfoEntity;
import com.sdry.model.zc.ZcMaterielAndTrayEntity;
import com.sdry.model.zc.ZcRejectsWarehouseEntity;
import com.sdry.model.zc.ZcSysUserEntity;
import com.sdry.model.zc.ZcTrayAndLocationEntity;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdry.model.inventoryInfoOnlyCountRejects.InventoryInfoOnlyCountRejects;
import com.sdry.model.jyy.Receive;
import com.sdry.model.jyy.ReceiveDetail;
import com.sdry.service.jyy.ReceiveDetailService;
import com.sdry.utils.BaseUtils;
import com.sdry.utils.DateUtil;
import com.sdry.mapper.inventoryInfoOnlyCountRejects.InventoryInfoOnlyCountRejectsMapper;
import com.sdry.mapper.jyy.ReceiveDetailMapper;
import com.sdry.mapper.jyy.ReceiveMapper;
import com.sdry.mapper.jyy.UpMapper;
/**
 *
 *@ClassName: ReceiveDetailService
 *@Description: 收货计划详情
 *@Author jyy
 *@Date 2019-04-19 14:30:17
 *@version 1.0
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class ReceiveDetailServiceImpl implements ReceiveDetailService {
	@Resource
    ReceiveDetailMapper ReceiveDetailMapper;
	@Resource
	private UpMapper upMapper;
	@Resource
	private ReceiveMapper receiveMapper;
	@Resource
	private InventoryInfoOnlyCountRejectsMapper inventoryInfoOnlyCountRejectsMapper;
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	public ReceiveDetail queryById(Long id) {
		return ReceiveDetailMapper.queryById(id);
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public List<ReceiveDetail> queryAllByMution(ReceiveDetail param) {
		
		
		return ReceiveDetailMapper.queryAllByMution(param);
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public List<ReceiveDetail> findPageByMution(ReceiveDetail param) {
		return ReceiveDetailMapper.findPageByMution(param);
	}
	/** 
	 * 条件查询记录数
	 * @param param 实体条件
	 * @return 实体集合
	*/
	public Integer selectCountByMution(ReceiveDetail param) {
		return ReceiveDetailMapper.selectCountByMution(param);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @return 主键id
	*/
	public Long insert(ReceiveDetail param) {
		return ReceiveDetailMapper.insert(param);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @return 影响行数
	*/
	public Integer update(ReceiveDetail param) {
		return ReceiveDetailMapper.update(param);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	public Integer delete(String ids) {
		return ReceiveDetailMapper.delete(ids);
	}
	
	/**
	 * 统计收货详情中有几条未收货的
	 */
	@Override
	public int countState(String receiveNumber) {
		return ReceiveDetailMapper.countState(receiveNumber);
	}

	/**
	 * 根据物料id查询物料实体
	 */
	@Override
	public Materiel queryMaterielByReceiveDetailId(Long mid) {
		return ReceiveDetailMapper.queryMaterielByReceiveDetailId(mid);
	}

	/**
	 * 添加每种物料对应的多个条码
	 * @param codeMark
	 */
	@Override
	public void addCodeMark(CodeMark codeMark) {
		ReceiveDetailMapper.addCodeMark(codeMark);
	}

	/**
	 * 根据收货单详细表id查询对应的条码
	 * @param receive_detail_id 收货单详细表id
	 * @throws Exception
	 */
	@Override
	public List<CodeMark> queryCodemarkByReceiveDetailId(String receive_detail_id) {
		return ReceiveDetailMapper.queryCodemarkByReceiveDetailId(receive_detail_id);
	}

	/**
	 * 根据mcode查询收货单详细
	 * @param mcode
	 * @return
	 */
	@Override
	public CodeMark queryReceiveDetailIdByMcode(String mcode) {
		return ReceiveDetailMapper.queryReceiveDetailIdByMcode(mcode);
	}

	/**
	 * 查询状态为1的收货单详细
	 * @throws Exception
	 */
	@Override
	public List<ReceiveDetail> selectAccurateByCodeApp(Long id) {
		return ReceiveDetailMapper.selectAccurateByCodeApp(id);
	}

	/**
	 * 新表添加数据
	 * @param receiveDetail
	 */
	@Override
	public void addReceiveDetailInstock(ReceiveDetail receiveDetail) {
		ReceiveDetailMapper.addReceiveDetailInstock(receiveDetail);
	}

	/**
	 * 质检表添加信息
	 * @param receiveDetail
	 */
	@Override
	public Long addReceiveDetailQuality(ReceiveDetail receiveDetail) {
		return ReceiveDetailMapper.addReceiveDetailQuality(receiveDetail);
	}

	/**
	 * 质检表修改信息
	 * @param receiveDetail
	 */
	@Override
	public void updateReceiveDetailQuality(ReceiveDetail receiveDetail) {
		ReceiveDetailMapper.updateReceiveDetailQuality(receiveDetail);
	}

	/**
	 * 分页查询质检单
	 * @param criteria
	 * @return
	 */
	@Override
	public List<ReceiveDetailQuality> queryReceiveDetailQualityCriteria(LzQueryCriteria criteria) {
		return ReceiveDetailMapper.queryReceiveDetailQualityCriteria(criteria);
	}

	/**
	 * 分页查询质检单数量
	 * @param criteria
	 * @return
	 */
	@Override
	public int countReceiveDetailQualityCriteria(LzQueryCriteria criteria) {
		return ReceiveDetailMapper.countReceiveDetailQualityCriteria(criteria);
	}

	/**
	 * 查询状态为0的质检表
	 * @return
	 */
	@Override
	public List<ReceiveDetailQuality> queryReceiveDetailQualityAPP(Long warehouse_id) {
		return ReceiveDetailMapper.queryReceiveDetailQualityAPP(warehouse_id);
	}

	/**
	 * 查询状态为1的质检表
	 * @return
	 */
	@Override
	public List<ReceiveDetailQuality> queryReceiveDetailQualityAPP1(Long warehouse_id) {
		return ReceiveDetailMapper.queryReceiveDetailQualityAPP1(warehouse_id);
	}

	/**
	 * 修改良品数和不良品数
	 * @param receiveDetailQuality
	 * @return
	 */
	@Override
	public Long updateReceiveDetailQualityAPP(ReceiveDetailQuality receiveDetailQuality) {
		return ReceiveDetailMapper.updateReceiveDetailQualityAPP(receiveDetailQuality);
	}

	/**
	 * 添加每种物料对应的工作量
	 * @param workload
	 */
	@Override
	public void addWorkload(Workload workload) {
		ReceiveDetailMapper.addWorkload(workload);
	}

	/**
	 * 绑定后修改质检的状态为2
	 * @param receiveDetailId
	 */
	@Override
	public void updateReceiveDetailQuality2(String receiveDetailId) {
		ReceiveDetailMapper.updateReceiveDetailQuality2(receiveDetailId);
	}

	/**
	 * 拆箱
	 * @param code
	 */
	@Override
	public void uncomeku(String code) {
		ReceiveDetailMapper.uncomeku(code);
	}
	
	/**
	 * 给不良品库存添加数据
	 * @param receiveDetailQuality
	 */
	@Override
	public void addZcRejectsWarehouseEntity(
			ReceiveDetailQuality receiveDetailQuality) {
		ReceiveDetailMapper.addZcRejectsWarehouseEntity(receiveDetailQuality);
	}
	
	/**
	 * 将库存表中的不良品数量减掉
	 * @param receiveDetailQuality
	 */
	@Override
	public void updateInventoryInfoNum(ReceiveDetailQuality receiveDetailQuality) {
		ReceiveDetailMapper.updateInventoryInfoNum(receiveDetailQuality);
	}
	
	/**
	 * 根据质检单详细表id查询对应的工作量
	 * @param receiveDetailQuality_id 质检单详细表id
	 * @throws Exception
	 */
	@Override
	public List<Workload> queryWorkloadByreceiveDetailQualityId(
			String receiveDetailQuality_id) {
		return ReceiveDetailMapper.queryWorkloadByreceiveDetailQualityId(receiveDetailQuality_id);
	}
	
	/**
	 * 根据批次和物料id查询不良品库是否存在该物料
	 */
	@Override
	public ZcRejectsWarehouseEntity queryZcRejectsWarehouseEntityByMbatchAngMid(
			ReceiveDetailQuality receiveDetailQuality) {
		return ReceiveDetailMapper.queryZcRejectsWarehouseEntityByMbatchAngMid(receiveDetailQuality);
	}
	
	/**
	 * 如果不良品库存在该物料就累加
	 */
	@Override
	public void updateZcRejectsWarehouseEntity(
			ReceiveDetailQuality receiveDetailQuality) {
		ReceiveDetailMapper.updateZcRejectsWarehouseEntity(receiveDetailQuality);
	}
	
	/**
	 * 根据精准码查询是否存在
	 * @param mcode
	 */
	@Override
	public CodeMark queryRepeatAccurateByCodeApp(String mcode) {
		return ReceiveDetailMapper.queryRepeatAccurateByCodeApp(mcode);
	}
	
	/**
	 * 查询有仓库操作员权限的人员
	 */
	@Override
	public List<String> queryRoleUser() {
		return ReceiveDetailMapper.queryRoleUser();
	}
	
	/**
	 * 质检表添加信息2
	 * @param receiveDetail
	 */
	@Override
	public Long addReceiveDetailQuality1(ReceiveDetail receiveDetail) {
		return ReceiveDetailMapper.addReceiveDetailQuality1(receiveDetail);
	}
	
	/**
	 * 根据条码修改条码状态
	 * @param code
	 */
	@Override
	public Long updateIsngStatus(String code) {
		return ReceiveDetailMapper.updateIsngStatus(code);
	}
	
	/**
	 * 根据条码查询物料和批次
	 * @param code
	 * @return
	 */
	@Override
	public ReceiveDetailQuality queryReceiveDetailQualityByCode(String code) {
		return ReceiveDetailMapper.queryReceiveDetailQualityByCode(code);
	}
	
	/**
	 * 修改CodeMark
	 * @param codeMark
	 * @return
	 */
	@Override
	public Long updateCodeMark(CodeMark codeMark) {
		return ReceiveDetailMapper.updateCodeMark(codeMark);
	}
	
	/**
	 * 根据CodeMark查询是否存在
	 * @param codemark
	 * @return
	 */
	@Override
	public CodeMark queryCodeMarkByCode(CodeMark codemark) {
		return ReceiveDetailMapper.queryCodeMarkByCode(codemark);
	}
	
	/**
	 * 根据收货单id查询CodeMark
	 * @param receive_detail_id
	 * @return
	 */
	@Override
	public List<CodeMark> queryCodeMarkById(String receive_detail_id) {
		return ReceiveDetailMapper.queryCodeMarkById(receive_detail_id);
	}
	
	/**
	 * 根据精准码修改质检区库存的数量
	 * @param mid 物料id
	 * @param pici 批次
	 * @param afterVal 差值数
	 */
	@Override
	public void updateInventoryInfoQuality(String mid, String pici,
			String afterVal) {
		ReceiveDetailMapper.updateInventoryInfoQuality(mid, pici, afterVal);
	}
	
	/**
	 * 绑定条码
	 * @param receiveMark
	 */
	@Override
	public void addReceiveMark(ReceiveMark receiveMark) {
		ReceiveDetailMapper.addReceiveMark(receiveMark);
	}
	
	/**
	 * 根据收货单id查询收货绑定实体
	 * @param receiveDetailId 收货单id
	 */
	@Override
	public List<ReceiveMark> queryReceiveMarkByReceiveId(String receiveDetailId) {
		return ReceiveDetailMapper.queryReceiveMarkByReceiveId(receiveDetailId);
	}
	
	/**
	 * 根据收货单id查询所有ReceiveMark实体
	 * @param receiveId 收货单id
	 * @param mcode
	 */
	@Override
	public ReceiveMark queryReceiveCodeByReceiveId(String receiveId,
			String mcode) {
		return ReceiveDetailMapper.queryReceiveCodeByReceiveId(receiveId, mcode);
	}
	
	/**
	 * 根据收货单详细id查询所有ReceiveMark实体
	 * @param receiveDetailId 收货单详细id
	 * @param receiveDetailId
	 */
	@Override
	public List<ReceiveMark> queryReceiveCodeByReceiveDetailId(String receiveDetailId) {
		return ReceiveDetailMapper.queryReceiveCodeByReceiveDetailId(receiveDetailId);
	}
	/**
	 * 根据收货单id查询条码
	 * @param receiveId 收货单id
	 */
	public List<ReceiveMark> selectReceiveMarkByReceiveId(Long receiveId) {
		return ReceiveDetailMapper.selectReceiveMarkByReceiveId(receiveId);
	}
	
	/**
	 * 根据条码查询是否包含
	 * @param code
	 * @return
	 */
	@Override
	public ZcMaterielAndTrayEntity queryMaterielTrayByCode(String code) {
		return ReceiveDetailMapper.queryMaterielTrayByCode(code);
	}
	
	/**
	 * 根据id替换条码
	 * @param indentity
	 * @param code
	 */
	@Override
	public void updateMaterielTrayByCode(String indentity, String code) {
		ReceiveDetailMapper.updateMaterielTrayByCode(indentity, code);
	}
	
	/**
	 * 根据物料id查询该质检表批次的该物料是否存在
	 * @param mid 物料id
	 * @param pici 批次
	 * @return
	 */
	@Override
	public ReceiveDetail queryReceiveDetaiQualityExsit(String mid, String pici, String receiveNumber) {
		return ReceiveDetailMapper.queryReceiveDetaiQualityExsit(mid, pici, receiveNumber);
	}
	
	/**     
	 * 根据ID删除记录   
	 * @param id    
	 */
	@Override
	public void deleteMaterielTrayById(Long id) {
		ReceiveDetailMapper.deleteMaterielTrayById(id);
	}
	/**       
	 * @param tray
	 * @return    
	 */
	@Override
	public ZcTrayAndLocationEntity queryTrayLocationByTray(String tray) {
		return ReceiveDetailMapper.queryTrayLocationByTray(tray);
	}
	/**       
	 * @param id    
	 */
	@Override
	public void deleteTrayLocationById(Long id) {
		ReceiveDetailMapper.deleteTrayLocationById(id);
	}
	/**       
	 * @param map    
	 */
	@Override
	public void updateQuantityByMidAndPici(Map<String, Object> map) {
		ReceiveDetailMapper.updateQuantityByMidAndPici(map);
	}
	
	/**
	 * 根据物料id和批次修改不质检的数量
	 * @param receiveDetail
	 * @return
	 */
	@Override
	public Long updateReceiveDetailQuality1(ReceiveDetail receiveDetail) {
		return ReceiveDetailMapper.updateReceiveDetailQuality1(receiveDetail);
	}
	
	/**
	 * 根据物料id和批次修改质检的数量
	 * @param receiveDetail
	 * @return
	 */
	@Override
	public Long updateReceiveDetailQuality3(ReceiveDetail receiveDetail) {
		return ReceiveDetailMapper.updateReceiveDetailQuality3(receiveDetail);
	}
	
	/**
	 * 根据物料id和批次查询修改的数据的主键
	 * @param receiveDetail
	 * @return
	 */
	@Override
	public Long queryIndentityByMidAndPici(ReceiveDetail receiveDetail) {
		return ReceiveDetailMapper.queryIndentityByMidAndPici(receiveDetail);
	}
	
	/**
	 * 根据托盘码查询物料托盘信息
	 * @param tray_code
	 * @return
	 */
	@Override
	public List<ZcMaterielAndTrayEntity> selectZcMaterielAndTrayEntityByTray(
			String tray_code) {
		return ReceiveDetailMapper.selectZcMaterielAndTrayEntityByTray(tray_code);
	}
	/**
	 * 不良品转良品
	 * @param code
	 * @return
	 */
	@Override
	public Long updateIsngStatus1(String code) {
		return ReceiveDetailMapper.updateIsngStatus1(code);
	}

	/**
	 * 新增条码转换记录:良品转不良品
	 * @param record
	 */
	@Override
	public void insertBarCodeConversionRecord(BarCodeConversionRecord record) {
		ReceiveDetailMapper.insertBarCodeConversionRecord(record);
	}

	/**
	 * 新增条码转换记录:不良品转良品(页面需确认)
	 * @param record
	 */
	@Override
	public void insertBarCodeConversionRecord1(BarCodeConversionRecord record) {
		ReceiveDetailMapper.insertBarCodeConversionRecord1(record);
	}

	/**
	 * 分页查询条码转换记录
	 * @param criteria
	 * @return
	 */
	@Override
	public List<BarCodeConversionRecord> queryBarCodeConversionRecordCriteria(LzQueryCriteria criteria) {
		return ReceiveDetailMapper.queryBarCodeConversionRecordCriteria(criteria);
	}

	/**
	 * 分页查询条码转换条数
	 * @param criteria
	 * @return
	 */
	@Override
	public int countBarCodeConversionRecordCriteria(LzQueryCriteria criteria) {
		return ReceiveDetailMapper.countBarCodeConversionRecordCriteria(criteria);
	}

	/**
	 * 良品转不良品确认
	 * @return
	 */
	@Override
	public Long updateConfirm(Long id) {
		return ReceiveDetailMapper.updateConfirm(id);
	}
	/**
	 * 根据物料id查询最早的批次
	 * @param mid 物料id
	 * @return 最早批次
	 */
	@Override
	public String selectOldPiciByMid(Long mid) {
		return ReceiveDetailMapper.selectOldPiciByMid(mid);
	}
	/**
	 * 根据条码查询ReceiveMark表
	 * @param mcode 条码
	 * @return ReceiveMark实体
	 */
	@Override
	public ReceiveMark selectReceiveMarkByCode(String mcode) {
		return ReceiveDetailMapper.selectReceiveMarkByCode(mcode);
	}
	
	/**
	 * 查询当前登录仓库对应的主机厂
	 * @param warehouseId
	 * @return
	 */
	@Override
	public List<Customer> queryThisWarehouseCustomer(Long warehouseId) {
		return ReceiveDetailMapper.queryThisWarehouseCustomer(warehouseId);
	}
	
	/**
	 * 根据收货单号查询单据合并标识
	 * @param receiveNumber
	 * @return
	 */
	@Override
	public String queryMergeFlag(String receiveNumber) {
		return ReceiveDetailMapper.queryMergeFlag(receiveNumber);
	}

    /**
     * 根据单据合并标识查询收货单详细
     * @param mergeFlag 单据合并标识
     * @return
     */
    @Override
    public List<ReceiveDetail> queryReceiveByMergeFlag(String mergeFlag) {
        return ReceiveDetailMapper.queryReceiveByMergeFlag(mergeFlag);
    }
    
	/**    
	 * 精简入库的提交   
	 * @param receiveNumber 收货单号
	 * @return    
	 */
	@Override
	public Integer submitReceiptFromLian(String receiveNumber) {
		Integer affact = 0;
		int num = 0;
		//获取仓库ID
		Long wareHouseId = BaseUtils.getSession();
		ZcSysUserEntity user = BaseUtils.getUserBySession();
		//1、根据收货单号查询收货单明细
		ReceiveDetail param = new ReceiveDetail();
		param.setReceiveNumber(receiveNumber);
		param.setWarehouse_id(wareHouseId);
		List<ReceiveDetail> receiveDetailList = ReceiveDetailMapper.queryAllByMution(param);
		//2、遍历收货单明细，修改收货数量，修改库存
		for(ReceiveDetail receiveDetail : receiveDetailList){
			receiveDetail.setCodeNum(receiveDetail.getTotalNum());
			//2.1、修改实际收货数量=预计发货数量
			Integer return1 = ReceiveDetailMapper.update(receiveDetail);
			//2.2、修改库存数量
			if(return1 > 0){
				Long l = updateInventory(receiveDetail);
				//如果修改成功，次数加1，最后判断，是否所有的明细都修改成功
				if(l > 0){
					num += 1;
				}else{
					break;
				}
			}else{
				break;
			}
		}
		//3、修改收货单的状态（如果收货单明细都修改成功）
		if(num == receiveDetailList.size()){
			//更改一级状态  --为已收货
			Receive receive = new Receive();
			receive.setReceiveNumber(receiveNumber);
			receive.setIsSimple("1");
			//3.1、查询收货单
			List<Receive> receives = receiveMapper.allByMution(receive);
			//3.2、改收货单状态
			if(receives.size()  > 0) {
				Receive receive2 = receives.get(0);
				receive2.setState(1);
				receive2.setReceiveDate(DateUtil.dateFormat3());
				receive2.setReceiveName(user.getId()+"");
				receive2.setSendCompany(null);
				//回收容器数量
				//receive2.setSureName(sure_name);
				Integer update = receiveMapper.update(receive2);
				if(update > 0){
					affact = 1;
				}
			}
		}
		return affact;
	}

    /**
	 * 根据收货单明细，修改精简库存
	 * @param receiveDetail 收货单明细的实体
	 * @return
	 */
	public Long updateInventory(ReceiveDetail receiveDetail){
		Long i = 0L;
		//获取仓库ID
		Long wareHouseId = BaseUtils.getSession();
		//登录人信息
		ZcSysUserEntity user = BaseUtils.getUserBySession();
		//日期
		String date = DateUtil.dateFormat3();
		Integer liang = receiveDetail.getCodeNum();
		if(liang > 0){
			//1、根据物料ID和批次，以及仓库ID，查询良品库存
			ZcInventoryInfoEntity zcInventoryInfoEntity = upMapper.selectByMid2(receiveDetail.getMid() + "", receiveDetail.getPici(),  wareHouseId.toString());
			if(zcInventoryInfoEntity != null){
				//1.1、如果有库存，修改库存数量
				int mNum = zcInventoryInfoEntity.getmNum();
				mNum = liang + mNum;
				//总数量（个数）
				zcInventoryInfoEntity.setmNum(mNum);
				i = upMapper.editStockOnlyCount(zcInventoryInfoEntity);
			}else{
				//1.2、如果没有库存，新增库存
				ZcInventoryInfoEntity zcInventoryInfoEntity1 = new ZcInventoryInfoEntity();
				zcInventoryInfoEntity1.setMid(receiveDetail.getMid());
				zcInventoryInfoEntity1.setmNum(receiveDetail.getCodeNum());
				zcInventoryInfoEntity1.setmBatch(receiveDetail.getPici());
				zcInventoryInfoEntity1.setEnterPerson(user.getId());
				zcInventoryInfoEntity1.setEnterDate(date);
				zcInventoryInfoEntity1.setWarehouse_id(wareHouseId);
				i = upMapper.insertStockOnlyCount(zcInventoryInfoEntity1);
			}
		}
		//3.2、根据物料ID和批次，以及仓库ID，查询不良品库存
		Integer buliang = receiveDetail.getNgNum();
		if(buliang > 0){
			InventoryInfoOnlyCountRejects inventoryInfoOnlyCountRejects = new InventoryInfoOnlyCountRejects();
			inventoryInfoOnlyCountRejects.setMid(receiveDetail.getMid());
			inventoryInfoOnlyCountRejects.setMbatch(receiveDetail.getPici());
			inventoryInfoOnlyCountRejects.setWarehouse_id(wareHouseId);
			List<InventoryInfoOnlyCountRejects> inventoryInfoOnlyCountRejectss = inventoryInfoOnlyCountRejectsMapper.queryAllByMution(inventoryInfoOnlyCountRejects);
			if(inventoryInfoOnlyCountRejectss.size() > 0){
				inventoryInfoOnlyCountRejects = inventoryInfoOnlyCountRejectss.get(0);
				int mNum = inventoryInfoOnlyCountRejects.getMnum();
				//1.如果是精准码,只存入总数
				mNum = buliang + mNum;
				//总数量（个数）
				inventoryInfoOnlyCountRejects.setMnum(mNum);
				Integer updateCount = inventoryInfoOnlyCountRejectsMapper.update(inventoryInfoOnlyCountRejects);
				i = updateCount.longValue();
			}else{
				inventoryInfoOnlyCountRejects.setMnum(receiveDetail.getNgNum());
				inventoryInfoOnlyCountRejects.setEnterperson(user.getId());
				inventoryInfoOnlyCountRejects.setEnterdate(date);
				i = inventoryInfoOnlyCountRejectsMapper.insert(inventoryInfoOnlyCountRejects);
			}
			inventoryInfoOnlyCountRejects = null;
		}
		return i;
	}

    /**
     * 查询单据中是否有重复的同批次的相同物料
     * @param receiveNumberStr
     * @return
     */
    @Override
    public Integer queryIsrepeated(String receiveNumberStr) {
        int err = 0;
        /*List<ReceiveDetail> receiveDetailLists = null;
        List<ReceiveDetail> data = null;*/
        List<ReceiveDetail> data = new ArrayList<>();
        List<ReceiveDetail> data_s = new ArrayList<>();
        if (receiveNumberStr != null) {
            String[] receiveNumberArr = receiveNumberStr.split(",");
            for (String receiveNumber : receiveNumberArr) {
                //根据收货单号查询收货单详细
                List<ReceiveDetail> receiveDetailList = ReceiveDetailMapper.queryReceiveDetailByReceiveId(receiveNumber);
                if (receiveDetailList.size() > 0) {
                    for (ReceiveDetail receiveDetail : receiveDetailList) {
                        data.add(receiveDetail);
                    }
                }
            }
        }

        for (ReceiveDetail s:data){
            if (data_s.size()==0){
                data_s.add(s);
            }else {
                int c=0;
                for (ReceiveDetail s1:data_s){
                    if (s1.getMateriel_num().equals(s.getMateriel_num())&&s1.getPici().equals(s.getPici())){
                        c=1;
                        err=1;
                        break;
                    }
                }
                if (c==0){
                    data_s.add(s);
                }
            }
        }
        return err;
    }

    /**
     * 根据收货单号查询提交状态
     * @param receiveNumber
     * @return
     */
    @Override
    public List<Receive> queryReceiveSubmitStatus(String receiveNumber) {
        return ReceiveDetailMapper.queryReceiveSubmitStatus(receiveNumber);
    }
}
